package com.mql.springcloud.controller;



import com.example.cloudapicommons.entity.CommonResult;
import com.example.cloudapicommons.entity.PaymentEntity;
import com.mql.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/maQingLin")
@Slf4j
public class PaymentController {
    @Autowired
    PaymentService paymentService;
    @Value("${server.port}")
    private String severPort;
    @PostMapping("/save")
    public CommonResult save(@RequestBody PaymentEntity pay){
        CommonResult commonResult=new CommonResult();
        int result=paymentService.add(pay);
        log.info("******"+result);
        if(result>0){
            commonResult.setCode(200);
            commonResult.setMessage("提交成功"+severPort);
        }
        else {
            commonResult.setCode(500);
            commonResult.setMessage("提交失败"+severPort);
        }
        return commonResult;
    }
    @GetMapping("/get/{id}")
    public CommonResult<PaymentEntity> get(@PathVariable("id") Integer id){
        CommonResult commonResult=new CommonResult();
        PaymentEntity paymentEntity=new PaymentEntity();
        paymentEntity=paymentService.getPaymentEntity(id);
        if(paymentEntity!=null){
            commonResult.setCode(200);
            commonResult.setMessage("查询成功"+severPort);
            commonResult.setData(paymentEntity);
        }
        else {
            commonResult.setCode(500);
            commonResult.setMessage("查询失败"+severPort);
            commonResult.setData(new Object());
        }
        return commonResult;
    }
}
